﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using OgilvyOne.Utility;

public partial class admin_manager_modelitemplate_modify : AdminBasePage
{
    public string labelname;
    public string labelvalue;
    public string labeldef;
    TemplateLabelBll bll = new TemplateLabelBll();
    TemplateLabelModel model = new TemplateLabelModel();
    int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PopedomValidate(layerid, MOD);
        id = int.Parse(Request.Params["id"]);
        model = bll.GetModel(id);
        labeldef = model.Def;
        labelname = model.Name;
        labelvalue = model.Value;
        
        if (!IsPostBack)
        {
            header.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);
            labeltype.Text = model.LabelType;
            name.Value = model.Name;
            value.InnerText = model.Value;
            def.Value = model.Def;

            if (model.Ishtml == 1)
            {
                htmlOk.Checked = true;
            }
            else
                htmlNo.Checked = true;
           
            if (model.Ishtml != 1)
            {
                htmlpp.Style.Add("display", "none");
                htmlp.Style.Add("display", "none");
            }
            htmlFileName.Text = model.HtmlFileName;
            modeltype.Text = model.ModelType.ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        model.Def = def.Value;
        model.Value = value.Value;
        model.Name = name.Value;
        model.LabelType = labeltype.Text;
        if (htmlFileName.Text != null)
            model.HtmlFileName = htmlFileName.Text;
        model.Ishtml = htmlOk.Checked ? 1 : 0;
        model.ModelType = int.Parse(modeltype.Text);
        if (name.Value == null || name.Value.Trim().ToString() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板名称不能为空！');", true);
            return;
        }
        if (def.Value == null || def.Value.Trim().ToString() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板定义不能为空！');", true);
            return;
        }
        if (value.Value == null || value.Value.Trim().ToString() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板值不能为空！');", true);
            return;
        }
        if (model.Ishtml == 1)
        {
            if (htmlFileName.Text == null || htmlFileName.Text == "")
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('HtmlFileName不能为空！');", true);
                return;
            }
        }
        if (!bll.Exists(name.Value, model.Id))
        {
            if (bll.Update(model))
            {
                
                string user = new AdminBasePage().GetSessionUsersModel().Username;
                this.insertLog(user + "修改模板标签名称" + labelname + "为： " + name.Value + "模板标签定义" + labeldef + "为：" + def.Value );
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('修改成功！');window.location=\"modellabel_manage.aspx?layerid=" + Layerid + "\"", true);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('修改失败！');window.location=\"modellabel_manage.aspx?layerid=" + Layerid + "\"", true);
            }
        }
        else
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('模板标签名称已存在！');", true);
    }
}
